﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinkGame.Models.Variations
{
    internal sealed class MovingCenterUpDownVariation : ApplicableVariation
    {
        protected override void DoApply(Map map, Point p1, Point p2)
        {
            if (p1.Y < map.Height / 2)
            {
                if (p2.Y < map.Height / 2)
                {
                    var maxY = map.Height / 2;
                    if (p1.X == p2.X)
                    {
                        MoveTilesOnPoint(map, p2, MovingDirection.Up, maxY: maxY);
                        MoveTilesOnPoint(map, p1, MovingDirection.Up, maxY: maxY);
                    }
                    else
                    {
                        MoveTilesOnPoint(map, p1, MovingDirection.Up, maxY: maxY);
                        MoveTilesOnPoint(map, p2, MovingDirection.Up, maxY: maxY);
                    }
                }
                else
                {
                    var yBoundary = map.Height / 2;
                    MoveTilesOnPoint(map, p1, MovingDirection.Up, maxY: yBoundary);
                    MoveTilesOnPoint(map, p2, MovingDirection.Down, minY: yBoundary);
                }
            }
            else
            {
                if (p2.Y < map.Height / 2)
                {
                    var yBoundary = map.Height / 2;
                    MoveTilesOnPoint(map, p1, MovingDirection.Down, minY: yBoundary);
                    MoveTilesOnPoint(map, p2, MovingDirection.Up, maxY: yBoundary);
                }
                else
                {
                    var minY = map.Height / 2;
                    if (p1.X == p2.X)
                    {
                        MoveTilesOnPoint(map, p1, MovingDirection.Down, minY: minY);
                        MoveTilesOnPoint(map, p2, MovingDirection.Down, minY: minY);
                    }
                    else
                    {
                        MoveTilesOnPoint(map, p2, MovingDirection.Down, minY: minY);
                        MoveTilesOnPoint(map, p1, MovingDirection.Down, minY: minY);
                    }
                }
            }
        }
    }
}
